package com.beyond.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.beyond.constant.ApplicationConstant;
import com.beyond.mapper.*;
import com.beyond.po.*;
import com.beyond.service.UserService;
import com.beyond.vo.BaseRespVO;
import com.beyond.vo.PaginaionVO;
import com.beyond.vo.safe.FireVO;
import com.beyond.vo.safe.SafeCapCountVO;
import com.beyond.vo.safe.SafecapVO;
import com.beyond.vo.user.*;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class UserServiceImpl implements UserService {

	private Logger logger = Logger.getLogger(UserServiceImpl.class);

	@Autowired
	private TUsersPOMapper usersPOMapper;
	@Autowired
	private TPersonPOMapper personPOMapper;
	@Autowired
	private TRecordPOMapper recordPOMapper;
    @Autowired
    private TRecordPOMapper_extend recordPOMapper_extend;
	@Autowired
    private TWorkingTimePOMapper workingTimePOMapper;
	@Autowired
    private TSafecapPOMapper safecapPOMapper;
	@Autowired
	private TFirePOMapper firePOMapper;


	@Transactional
	@Override
	public BaseRespVO insertUser(UserAddReqVO reqVO) throws Exception{
		
		if(reqVO == null ){
			throw new RuntimeException("请求参数为空！");
		}
		if (StringUtils.isBlank(reqVO.getUsername())) {
			throw new RuntimeException("请求参数【用户名】为空！");
		}
		if (StringUtils.isBlank(reqVO.getPassword())) {
			throw new RuntimeException("请求参数【密码】为空！");
		}

		TUsersPO record = new TUsersPO();
		record.setUsername(reqVO.getUsername());
		record.setPassword(reqVO.getPassword());
		usersPOMapper.insert(record);

		BaseRespVO respVO = new BaseRespVO();
		respVO.setResult(ApplicationConstant.RESULT_SUCCESS);
		respVO.setMsg("新增用户成功");
		return respVO;
	}

	@Transactional
	@Override
	public BaseRespVO updateUser(UserAddReqVO reqVO)
			throws Exception {
		if(reqVO == null ){
			throw new RuntimeException("请求参数为空！");
		}
		if(null == reqVO.getId()){
			throw new RuntimeException("用户标识符不能为空！");
		}

		TUsersPO po = new TUsersPO();
		BeanUtils.copyProperties(reqVO,po);
		usersPOMapper.updateByPrimaryKeySelective(po);
		
		BaseRespVO respVO = new BaseRespVO();
		respVO.setResult(ApplicationConstant.RESULT_SUCCESS);
		return respVO;
	}

	@Override
	public BaseRespVO deleteUser(UserAddReqVO reqVO) throws Exception {
		if(reqVO == null ){
			throw new RuntimeException("请求参数为空！");
		}
		if(null == reqVO.getId()){
			throw new RuntimeException("用户标识符不能为空！");
		}

		usersPOMapper.deleteByPrimaryKey(reqVO.getId());

		BaseRespVO respVO = new BaseRespVO();
		respVO.setResult(ApplicationConstant.RESULT_SUCCESS);
		respVO.setMsg("删除用户成功！");
		return respVO;
	}

	@Override
	public PaginaionVO<UserAddReqVO> selectUserList(UserAddReqVO req, int page, int pageSize) throws Exception {
		PaginaionVO<UserAddReqVO> respVO = new PaginaionVO<UserAddReqVO>();
		if(req == null){
			respVO.setResult(ApplicationConstant.RESULT_FALTURE);
			respVO.setMsg("请求参数为空！");
			logger.error(respVO.getMsg());
			return respVO;
		}
		List<UserAddReqVO> userList = new ArrayList<UserAddReqVO>();
		PageHelper.startPage(page, pageSize);
		TUsersPOExample example = new TUsersPOExample();
		TUsersPOExample.Criteria criteria = example.createCriteria();
		if(StringUtils.isNotBlank(req.getUsername())){
			criteria.andUsernameLike("%"+req.getUsername()+"%");
		}
		List<TUsersPO> list = usersPOMapper.selectByExample(example);
		PageInfo<TUsersPO> pageInfo = new PageInfo<TUsersPO>(list);
		respVO.setTotalPage(pageInfo.getPages());
		respVO.setTotal((int) pageInfo.getTotal());
		if(null != list && list.size() > 0){
			for(TUsersPO po : list){
				UserAddReqVO vo = new UserAddReqVO();
				BeanUtils.copyProperties(po, vo);
				userList.add(vo);
			}
		}
		respVO.setRows(userList);
		respVO.setResult(ApplicationConstant.RESULT_SUCCESS);
		respVO.setMsg("获取用户列表成功！");
		return respVO;
	}

	@Override
	public PaginaionVO<PersonVO> selectPersonList(PersonVO reqVO, int page, int pageSize) throws Exception {
		if(reqVO == null ){
			throw new RuntimeException("请求参数为空！");
		}
		// 默认分页参数
		if (page == 0) {
			page = 1;
		}
		if (pageSize == 0) {
			pageSize = 10;
		}
		PageHelper.startPage(page, pageSize);

		TPersonPOExample example = new TPersonPOExample();
		TPersonPOExample.Criteria criteria = example.createCriteria();
		if(null != reqVO.getIdnum()){
			criteria.andIdnumEqualTo(reqVO.getIdnum());
		}
		if(StringUtils.isNotBlank(reqVO.getName())){
			criteria.andNameLike("%"+reqVO.getName()+"%");
		}
		if(StringUtils.isNotBlank(reqVO.getCategory())){
			criteria.andCategoryLike("%"+reqVO.getCategory()+"%");
		}
		List<TPersonPO> POs = personPOMapper.selectByExample(example);
		PageInfo<TPersonPO> pageInfo = new PageInfo<TPersonPO>(POs);
		int pages = pageInfo.getPages();
		long total = pageInfo.getTotal();
		
		List<PersonVO> rows = new ArrayList<PersonVO>();
		if(POs != null && POs.size() >0){
			for (TPersonPO po : POs) {
				PersonVO vo = new PersonVO();
				BeanUtils.copyProperties(po, vo);
				if(StringUtils.isNotBlank(po.getIdnum())){
					String birthYear = po.getIdnum().substring(6, 10);
					DateFormat dateFormat = new SimpleDateFormat("yyyy");
					Date today = new Date();
					String todayString = dateFormat.format(today);
					vo.setAge(Integer.parseInt(todayString) - Integer.parseInt(birthYear));
				}
				rows.add(vo);
			}
		}
		
		PaginaionVO<PersonVO> paginaionVO = new PaginaionVO<PersonVO>();
		paginaionVO.setCurrPage(page);
		paginaionVO.setPageSize(pageSize);
		paginaionVO.setTotal(total);
		paginaionVO.setTotalPage(pages);
		paginaionVO.setRows(rows);
		paginaionVO.setResult(ApplicationConstant.RESULT_SUCCESS);
		paginaionVO.setMsg("查询人员列表成功");
		return paginaionVO;
	}

	@Override
	public PaginaionVO<PersonAgeCountVO> selectPersonAgeCount(PersonAgeCountVO req) throws Exception {

		PaginaionVO<PersonAgeCountVO> respVO = new PaginaionVO<PersonAgeCountVO>();

		DateFormat yearFormat = new SimpleDateFormat("yyyy");

		PersonAgeCountVO vo18low = new PersonAgeCountVO();
		PersonAgeCountVO vo1825 = new PersonAgeCountVO();
		PersonAgeCountVO vo2530 = new PersonAgeCountVO();
		PersonAgeCountVO vo3040 = new PersonAgeCountVO();
		PersonAgeCountVO vo4050 = new PersonAgeCountVO();
		PersonAgeCountVO vo50up = new PersonAgeCountVO();

		Date dNow = new Date();       //当前时间
		Date d18Before;    //18年前的时间
		Date d25Before;    //25年前的时间
		Date d30Before;    //30年前的时间
		Date d40Before;    //40年前的时间
		Date d50Before;    //50年前的时间

		Calendar calendar = Calendar.getInstance(); //得到日历
		calendar.setTime(dNow);//把当前时间赋给日历
		calendar.add(calendar.YEAR, -18);  //设置为前18年
		d18Before = calendar.getTime();   //得到前18年前的时间

		calendar.setTime(dNow);//把当前时间赋给日历
		calendar.add(calendar.YEAR, -25);  //设置为前25年
		d25Before = calendar.getTime();   //得到前25年前的时间

		calendar.setTime(dNow);//把当前时间赋给日历
		calendar.add(calendar.YEAR, -30);
		d30Before = calendar.getTime();

		calendar.setTime(dNow);//把当前时间赋给日历
		calendar.add(calendar.YEAR, -40);
		d40Before = calendar.getTime();

		calendar.setTime(dNow);//把当前时间赋给日历
		calendar.add(calendar.YEAR, -50);
		d50Before = calendar.getTime();

		Map<String, Object> params = new HashMap<String, Object>();
		params.put("beginDate", yearFormat.format(d18Before));
		params.put("endDate", yearFormat.format(dNow));
		int po18low = recordPOMapper_extend.countPersonByExample(params);
		vo18low.setCount(po18low);
		vo18low.setAge("0-18岁");

		params.put("beginDate", yearFormat.format(d25Before));
		params.put("endDate", yearFormat.format(d18Before));
		int po1825 = recordPOMapper_extend.countPersonByExample(params);
		vo1825.setCount(po1825);
		vo1825.setAge("18-25岁");

		params.put("beginDate", yearFormat.format(d30Before));
		params.put("endDate", yearFormat.format(d25Before));
		int po2530 = recordPOMapper_extend.countPersonByExample(params);
		vo2530.setCount(po2530);
		vo2530.setAge("25-30岁");

		params.put("beginDate", yearFormat.format(d40Before));
		params.put("endDate", yearFormat.format(d30Before));
		int po3040 = recordPOMapper_extend.countPersonByExample(params);
		vo3040.setCount(po3040);
		vo3040.setAge("30-40岁");

		params.put("beginDate", yearFormat.format(d50Before));
		params.put("endDate", yearFormat.format(d40Before));
		int po4050 = recordPOMapper_extend.countPersonByExample(params);
		vo4050.setCount(po4050);
		vo4050.setAge("40-50岁");

		params.put("beginDate", null);
		params.put("endDate", yearFormat.format(d50Before));
		int po50up = recordPOMapper_extend.countPersonByExample(params);
		vo50up.setCount(po50up);
		vo50up.setAge("50以上");

		List<PersonAgeCountVO> rows = new ArrayList<PersonAgeCountVO>();
		rows.add(vo18low);
		rows.add(vo1825);
		rows.add(vo2530);
		rows.add(vo3040);
		rows.add(vo4050);
		rows.add(vo50up);

		respVO.setRows(rows);
		respVO.setTotal(6);
		respVO.setTotalPage(6);
		respVO.setResult(ApplicationConstant.RESULT_SUCCESS);
		respVO.setMsg("获取人员年龄分布成功！");
		return respVO;
	}

	@Override
	public PaginaionVO<PersonSourceCountVO> selectPersonSourceCount(PersonSourceCountVO req, int page, int pageSize) throws Exception {
		PaginaionVO<PersonSourceCountVO> respVO = new PaginaionVO<PersonSourceCountVO>();

		PageHelper.startPage(page, pageSize);

		List<PersonSourceCountVO> list = recordPOMapper_extend.countPersonSource();
		PageInfo<PersonSourceCountVO> pageInfo = new PageInfo<PersonSourceCountVO>(list);

		respVO.setTotalPage(pageInfo.getPages());
		respVO.setTotal((int) pageInfo.getTotal());
		respVO.setRows(list);
		respVO.setResult(ApplicationConstant.RESULT_SUCCESS);
		respVO.setMsg("获取人员来源分布列表成功！");
		return respVO;
	}

	@Override
	public PaginaionVO<RecordVO> selectRecordList(RecordVO req, int page, int pageSize) throws Exception {
		PaginaionVO<RecordVO> respVO = new PaginaionVO<RecordVO>();
		if(req == null){
			respVO.setResult(ApplicationConstant.RESULT_FALTURE);
			respVO.setMsg("请求参数为空！");
			logger.error(respVO.getMsg());
			return respVO;
		}
		List<RecordVO> recordVOList = new ArrayList<RecordVO>();
		PageHelper.startPage(page, pageSize);
		TRecordPOExample example = new TRecordPOExample();
		TRecordPOExample.Criteria criteria = example.createCriteria();
		if(null != req.getIdnum()){
			criteria.andIdnumEqualTo(req.getIdnum());
		}
		if(StringUtils.isNotBlank(req.getName())){
			criteria.andNameLike("%"+req.getName()+"%");
		}
		if(StringUtils.isNotBlank(req.getCategory())){
			criteria.andCategoryLike("%"+req.getCategory()+"%");
		}
		if(StringUtils.isNotBlank(req.getDatebegin())){
			criteria.andRecotimeGreaterThanOrEqualTo(ApplicationConstant.dateTimeFormat.parse(req.getDatebegin()));
		}
		if(StringUtils.isNotBlank(req.getDateend())){
			criteria.andRecotimeLessThanOrEqualTo(ApplicationConstant.dateTimeFormat.parse(req.getDateend()));
		}
		List<TRecordPO> list = recordPOMapper.selectByExample(example);
		PageInfo<TRecordPO> pageInfo = new PageInfo<TRecordPO>(list);
		respVO.setTotalPage(pageInfo.getPages());
		respVO.setTotal((int) pageInfo.getTotal());
		if(null != list && list.size() > 0){
			for(TRecordPO po : list){
				RecordVO vo = new RecordVO();
				BeanUtils.copyProperties(po, vo);
				if (po.getRecotime() != null) {
					vo.setRecotime(ApplicationConstant.dateTimeFormat.format(po.getRecotime()));
				}
				recordVOList.add(vo);
			}
		}
		respVO.setRows(recordVOList);
		respVO.setResult(ApplicationConstant.RESULT_SUCCESS);
		respVO.setMsg("获取记录列表成功！");
		return respVO;
	}

    @Override
    public PaginaionVO<RecordCountVO> selectRecordCount(RecordCountVO req, int page, int pageSize) throws Exception {
		PaginaionVO<RecordCountVO> respVO = new PaginaionVO<RecordCountVO>();
		if(req == null){
			respVO.setResult(ApplicationConstant.RESULT_FALTURE);
			respVO.setMsg("请求参数为空！");
			logger.error(respVO.getMsg());
			return respVO;
		}

		List<RecordCountVO> list = new ArrayList<RecordCountVO>();
		PageHelper.startPage(page, pageSize);

		Date dNow = new Date();       //当前时间
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("beginDate", ApplicationConstant.dateTimeFormat.parse(dateFormat.format(dNow)+" 06:00:00"));
		List<RecordCountVO> recordList = recordPOMapper_extend.countRecordByExample(params);
		PageInfo<RecordCountVO> pageInfo = new PageInfo<RecordCountVO>(recordList);
		respVO.setTotalPage(pageInfo.getPages());
		respVO.setTotal((int) pageInfo.getTotal());
		if(null != recordList && recordList.size() >0){
			for(RecordCountVO po : recordList){
				RecordCountVO vo = new RecordCountVO();
				BeanUtils.copyProperties(po, vo);
				if (po.getInperson() != null && po.getOutperson() != null) {
					Integer currentperson = po.getInperson() - po.getOutperson();
					if (currentperson < 0) {
						currentperson = 0;
					}
					vo.setCurrentperson(currentperson);
				}
				list.add(vo);
			}
		}

		respVO.setRows(list);
		respVO.setResult(ApplicationConstant.RESULT_SUCCESS);
		respVO.setMsg("获取人员情况汇总列表成功！");
		return respVO;
    }

    @Override
	public PaginaionVO<WorkingTimeVO> selectWorkingTimeList(WorkingTimeVO req, int page, int pageSize) throws Exception {
		PaginaionVO<WorkingTimeVO> respVO = new PaginaionVO<WorkingTimeVO>();
		if(req == null){
			respVO.setResult(ApplicationConstant.RESULT_FALTURE);
			respVO.setMsg("请求参数为空！");
			logger.error(respVO.getMsg());
			return respVO;
		}
		List<WorkingTimeVO> workingTimeVOList = new ArrayList<WorkingTimeVO>();
		PageHelper.startPage(page, pageSize);
		TWorkingTimePOExample example = new TWorkingTimePOExample();
		TWorkingTimePOExample.Criteria criteria = example.createCriteria();
		if(StringUtils.isNotBlank(req.getDatebegin())){
			criteria.andIntimeGreaterThanOrEqualTo(ApplicationConstant.dateTimeFormat.parse(req.getDatebegin()));
		}
		if(StringUtils.isNotBlank(req.getDateend())){
			criteria.andIntimeLessThanOrEqualTo(ApplicationConstant.dateTimeFormat.parse(req.getDateend()));
		}
		if(StringUtils.isNotBlank(req.getName())){
			criteria.andNameLike("%"+req.getName()+"%");
		}
		List<TWorkingTimePO> list = workingTimePOMapper.selectByExample(example);
		PageInfo<TWorkingTimePO> pageInfo = new PageInfo<TWorkingTimePO>(list);
		respVO.setTotalPage(pageInfo.getPages());
		respVO.setTotal((int) pageInfo.getTotal());
		if(null != list && list.size() > 0){
			for(TWorkingTimePO po : list){
				WorkingTimeVO vo = new WorkingTimeVO();
				BeanUtils.copyProperties(po, vo);
				if (po.getIntime() != null) {
					vo.setIntime(ApplicationConstant.dateTimeFormat.format(po.getIntime()));
				}
				if (po.getOuttime() != null) {
					vo.setOuttime(ApplicationConstant.dateTimeFormat.format(po.getOuttime()));
				}
				workingTimeVOList.add(vo);
			}
		}
		respVO.setRows(workingTimeVOList);
		respVO.setResult(ApplicationConstant.RESULT_SUCCESS);
		respVO.setMsg("获取工作时长列表成功！");
		return respVO;
	}

	@Override
	public PaginaionVO<SafecapVO> selectSafeCapList(SafecapVO req, int page, int pageSize) throws Exception {
		PaginaionVO<SafecapVO> respVO = new PaginaionVO<SafecapVO>();
		if(req == null){
			respVO.setResult(ApplicationConstant.RESULT_FALTURE);
			respVO.setMsg("请求参数为空！");
			logger.error(respVO.getMsg());
			return respVO;
		}
		List<SafecapVO> safecapList = new ArrayList<SafecapVO>();
		PageHelper.startPage(page, pageSize);

		TSafecapPOExample example = new TSafecapPOExample();
		TSafecapPOExample.Criteria criteria = example.createCriteria();
		if (StringUtils.isNotBlank(req.getCameraip())) {
			criteria.andCameraipEqualTo(req.getCameraip());
		}
		if (StringUtils.isNotBlank(req.getDatebegin())) {
			criteria.andDatetimeGreaterThanOrEqualTo(req.getDatebegin());
		}
		if (StringUtils.isNotBlank(req.getDateend())) {
			criteria.andDatetimeLessThanOrEqualTo(req.getDateend());
		}
		example.setOrderByClause("dateTime DESC");
		List<TSafecapPO> list = safecapPOMapper.selectByExample(example);
		PageInfo<TSafecapPO> pageInfo = new PageInfo<TSafecapPO>(list);
		respVO.setTotalPage(pageInfo.getPages());
		respVO.setTotal((int) pageInfo.getTotal());
		if(null != list && list.size() > 0){
			for(TSafecapPO po : list){
				SafecapVO vo = new SafecapVO();
				BeanUtils.copyProperties(po, vo);				
				safecapList.add(vo);
			}
		}
		respVO.setRows(safecapList);
		respVO.setResult(ApplicationConstant.RESULT_SUCCESS);
		respVO.setMsg("获取安全帽佩戴检测列表成功！");
		return respVO;
	}

	@Override
	public PaginaionVO<FireVO> selectFireList(FireVO req, int page, int pageSize) throws Exception {
		PaginaionVO<FireVO> respVO = new PaginaionVO<FireVO>();
		if(req == null){
			respVO.setResult(ApplicationConstant.RESULT_FALTURE);
			respVO.setMsg("请求参数为空！");
			logger.error(respVO.getMsg());
			return respVO;
		}
		List<FireVO> fireList = new ArrayList<FireVO>();
		PageHelper.startPage(page, pageSize);

		TFirePOExample example = new TFirePOExample();
		TFirePOExample.Criteria criteria = example.createCriteria();
		if (StringUtils.isNotBlank(req.getCameraip())) {
			criteria.andCameraipEqualTo(req.getCameraip());
		}
		if (StringUtils.isNotBlank(req.getDatebegin())) {
			criteria.andDatetimeGreaterThanOrEqualTo(req.getDatebegin());
		}
		if (StringUtils.isNotBlank(req.getDateend())) {
			criteria.andDatetimeLessThanOrEqualTo(req.getDateend());
		}
        example.setOrderByClause("dateTime DESC");
		List<TFirePO> list = firePOMapper.selectByExample(example);
		PageInfo<TFirePO> pageInfo = new PageInfo<TFirePO>(list);
		respVO.setTotalPage(pageInfo.getPages());
		respVO.setTotal((int) pageInfo.getTotal());
		if(null != list && list.size() > 0){
			for(TFirePO po : list){
				FireVO vo = new FireVO();
				BeanUtils.copyProperties(po, vo);
				fireList.add(vo);
			}
		}
		respVO.setRows(fireList);
		respVO.setResult(ApplicationConstant.RESULT_SUCCESS);
		respVO.setMsg("获取火灾预警列表成功！");
		return respVO;
	}

	@Override
	public PaginaionVO<FireVO> selectHistoryAlarmList(FireVO req, int page, int pageSize) throws Exception {
		PaginaionVO<FireVO> respVO = new PaginaionVO<FireVO>();
		if(req == null){
			respVO.setResult(ApplicationConstant.RESULT_FALTURE);
			respVO.setMsg("请求参数为空！");
			logger.error(respVO.getMsg());
			return respVO;
		}
		List<FireVO> fireList = new ArrayList<FireVO>();
		//查询火灾预警列表
		TFirePOExample example = new TFirePOExample();
		TFirePOExample.Criteria criteria = example.createCriteria();
		if (StringUtils.isNotBlank(req.getCameraip())) {
			criteria.andCameraipEqualTo(req.getCameraip());
		}
		if (StringUtils.isNotBlank(req.getDatebegin())) {
			criteria.andDatetimeGreaterThanOrEqualTo(req.getDatebegin());
		}
		if (StringUtils.isNotBlank(req.getDateend())) {
			criteria.andDatetimeLessThanOrEqualTo(req.getDateend());
		}
        example.setOrderByClause("dateTime DESC");
		List<TFirePO> list = firePOMapper.selectByExample(example);
		if(null != list && list.size() > 0){
			for(TFirePO po : list){
				FireVO vo = new FireVO();
				BeanUtils.copyProperties(po, vo);
				fireList.add(vo);
			}
            respVO.setTotal(list.size());
		}
		//查询安全帽佩戴检测列表
		TSafecapPOExample example2 = new TSafecapPOExample();
		TSafecapPOExample.Criteria criteria2 = example2.createCriteria();
		if (StringUtils.isNotBlank(req.getCameraip())) {
			criteria2.andCameraipEqualTo(req.getCameraip());
		}
		if (StringUtils.isNotBlank(req.getDatebegin())) {
			criteria2.andDatetimeGreaterThanOrEqualTo(req.getDatebegin());
		}
		if (StringUtils.isNotBlank(req.getDateend())) {
			criteria2.andDatetimeLessThanOrEqualTo(req.getDateend());
		}
        example2.setOrderByClause("dateTime DESC");
		List<TSafecapPO> list2 = safecapPOMapper.selectByExample(example2);
		if(null != list2 && list2.size() > 0){
			for(TSafecapPO po : list2){
				FireVO vo = new FireVO();
				BeanUtils.copyProperties(po, vo);
				fireList.add(vo);
			}
			respVO.setTotal(respVO.getTotal()+list2.size());
		}

		respVO.setRows(fireList);
		respVO.setResult(ApplicationConstant.RESULT_SUCCESS);
		respVO.setMsg("获取历史报警查询列表成功！");
		return respVO;
	}

	@Override
	public PaginaionVO<SafeCapCountVO> selectSafeCatCount(SafeCapCountVO req) throws Exception {
		PaginaionVO<SafeCapCountVO> respVO = new PaginaionVO<SafeCapCountVO>();

		List<SafeCapCountVO> list = recordPOMapper_extend.countSafeCap();

		respVO.setRows(list);
		respVO.setResult(ApplicationConstant.RESULT_SUCCESS);
		respVO.setMsg("获取安全帽佩戴检测列表成功！");
		return respVO;
	}

    @Override
    public PaginaionVO<SafeCapCountVO> selectFireAlarmCount(SafeCapCountVO req) throws Exception {
        PaginaionVO<SafeCapCountVO> respVO = new PaginaionVO<SafeCapCountVO>();

        List<SafeCapCountVO> list = recordPOMapper_extend.countFireAlarm();

        respVO.setRows(list);
        respVO.setResult(ApplicationConstant.RESULT_SUCCESS);
        respVO.setMsg("获取火灾预警次数统计成功！");
        return respVO;
    }

}
